package com.bdqn.controller;

import com.bdqn.pojo.BackendUser;
import com.bdqn.pojo.DevUser;
import com.bdqn.service.BackendUserService;
import com.bdqn.service.DevUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController extends BaseController{
    @Resource
    private BackendUserService backendUserService;
    @Resource
    private DevUserService devUserService;
    @RequestMapping(value="/dev",method = RequestMethod.POST)
    public String dev(@RequestParam("username")String username, @RequestParam("password")String password, HttpSession session){
           DevUser dev=devUserService.login(username,password);
           if(dev!=null){
               session.setAttribute("user",dev);
               session.setAttribute("id",1);
               return "jsp/index";
           }else {
               return "redirect:login.jsp";
           }

    }
    @RequestMapping(value="/backd",method = RequestMethod.POST)
    public String backd(@RequestParam("username")String username,@RequestParam("password")String password,HttpSession session){
BackendUser dev=backendUserService.login(username,password);
        if(dev!=null){
            session.setAttribute("user",dev);
            session.setAttribute("id",2);
            return "jsp/indexbac";
        }else {
            return "redirect:login.jsp";
        }

    }

    @RequestMapping(value="/dele")
    public String dele(HttpSession session){
        session.removeAttribute("user");
        session.removeAttribute("id");
        return "redirect:login.jsp";
    }


}
